package cn.com.se.设计模式.享元模式;

import java.util.HashMap;
import java.util.Map;

public class ChessPieceFactory {
    private static final Map<String, ChessPiece> pieces = new HashMap<>();

    public static ChessPiece getPiece(String color, String type) {
        String key = color + "_" + type;
        if (!pieces.containsKey(key)) {
            pieces.put(key, new ConcreteChessPiece(color, type));
            System.out.println("创建新棋子：" + key);
        }
        return pieces.get(key);
    }
}
